#include<stdio.h>         
#include <sys/types.h>    
#include <sys/socket.h>   
#include <stdlib.h>      
#include <netinet/in.h>   
#include <arpa/inet.h>   
 #include <string.h>

int main(int argc, const char *argv[])
{
	int sockfd;
	char buf[32]={0};
	sockfd=socket(AF_INET,SOCK_STREAM,0);
	if(sockfd<0)
	{
	  perror("sockfd err");
	  exit(-1);
	}
	printf("fockfd ok\n");

	struct sockaddr_in clientaddr;
	clientaddr.sin_family=AF_INET;
	clientaddr.sin_port=htons(atoi(argv[2]));
	clientaddr.sin_addr.s_addr=inet_addr(argv[1]);
	socklen_t clilen=sizeof(clientaddr);

	if(connect(sockfd,(struct sockaddr *)&clientaddr,clilen)<0)
	{
	  perror("connect err");
	  exit(-1);
	}
	printf("connect ok\n");

	while(1)
	{
	  fgets(buf,sizeof(buf),stdin);
	  buf[strlen(buf)-1] = '\0';
	 // buf[strlen(buf)-1]='\0';
	  send(sockfd,buf,sizeof(buf),0);
	}
	return 0;
}
